#import "NotesString.h"

@implementation NotesString

- (id)init
{
	if(!self) {
		self = [super init];
	}
	notes = [[NSArray arrayWithObjects:@"A",@"As",@"B",@"C",@"Cs",@"D",@"Ds",@"E",@"F",@"Fs",@"G",@"Gs", nil] retain];
	notesString = [[NSArray arrayWithObjects:@"A",@"A#",@"B",@"C",@"C#",@"D",@"D#",@"E",@"F",@"F#",@"G",@"G#", nil] retain];
	openStringNotes = [[NSArray arrayWithObjects:@"E",@"A",@"D",@"G",@"B",@"E", nil] retain];
	allStringNotes = [[NSArray arrayWithObjects:
	[[NSArray arrayWithObjects:@"E",@"F",@"F#",@"G",@"G#",@"A",@"A#",@"B",@"C",@"C#",@"D",@"D#",@"E",@"F",@"F#",@"G",@"G#",@"A",@"A#",@"B",@"C", nil] retain],
	[[NSArray arrayWithObjects:@"A",@"A#",@"B",@"C",@"C#",@"D",@"D#",@"E",@"F",@"F#",@"G",@"G#",@"A",@"A#",@"B",@"C",@"C#",@"D",@"D#",@"E",@"F", nil] retain],
	[[NSArray arrayWithObjects:@"D",@"D#",@"E",@"F",@"F#",@"G",@"G#",@"A",@"A#",@"B",@"C",@"C#",@"D",@"D#",@"E",@"F",@"F#",@"G",@"G#",@"A",@"A#", nil] retain],
	[[NSArray arrayWithObjects:@"G",@"G#",@"A",@"A#",@"B",@"C",@"C#",@"D",@"D#",@"E",@"F",@"F#",@"G",@"G#",@"A",@"A#",@"B",@"C",@"C#",@"D",@"D#", nil] retain],
	[[NSArray arrayWithObjects:@"B",@"C",@"C#",@"D",@"D#",@"E",@"F",@"F#",@"G",@"G#",@"A",@"A#",@"B",@"C",@"C#",@"D",@"D#",@"E",@"F",@"F#",@"G", nil] retain],
	[[NSArray arrayWithObjects:@"E",@"F",@"F#",@"G",@"G#",@"A",@"A#",@"B",@"C",@"C#",@"D",@"D#",@"E",@"F",@"F#",@"G",@"G#",@"A",@"A#",@"B",@"C", nil] retain],
	nil] retain];

	return self;
}

- (NSString*)show:(NSString*)note
{
	return [notesString objectAtIndex:[notes indexOfObject:note]];
}

- (int)getNumberOfStrings
{
	return [allStringNotes count];
}

- (NSString*)getNoteFromString:(int)stringNumber position:(int)pos
{
	return [[allStringNotes objectAtIndex:stringNumber] objectAtIndex:pos];
}

- (NSString*)getNoteFromOpenString:(int)stringNumber
{
	return [openStringNotes objectAtIndex:stringNumber];
}

/*
- (int)getNote:(NSString*)note string:(int)stringNumber from:(int)start to:(int)end
{
	return [[allStringNotes objectAtIndex:stringNumber] indexOfObject:note inRange:NSMakeRange(start,end-start)];
}
*/
- (NSString*)getSuccNote:(NSString*)note delta:(int)interval
{
	int posNote = [notes indexOfObject:note];
	return [notes objectAtIndex:((posNote+interval) % 12)];
}
/*
- (NSString*)getNoteFromString:(int)string atPosition:(int)position
{
	NSString *openString=[openStringNotes objectAtIndex:string];
	return [notesString objectAtIndex:(([notes indexOfObject:openString]+position) % 12)];
}
*/
/*
- (int)getMinNote:(NSString*)note
{
	// NSLog(@"cerco %@",note);
	int i,posOpenString,posNote,index;
	for (i=0;i<[openStringNotes count];i++)
	{
		NSString *string=[openStringNotes objectAtIndex:i];
		// NSLog(@"cerco su openString %@",string);
		posOpenString = [notes indexOfObject:string];
		posNote = [notes indexOfObject:note];
		// NSLog(@"posOpenString %d - posNote %d",posOpenString,posNote);
		if (posNote<posOpenString) posNote+=12;
		if (posNote-posOpenString<6)
		{
			index=posNote-posOpenString+(i*24);
			// NSLog(@"trovata posizione %d",index);
			break;
		}
	}
	return index;
}
*/
/*
- (int)getMinNote:(NSString*)note from:(int)start
{
	// NSLog(@"cerco %@ from %d",note,start);
	int i,posOpenString,posNote,index;
	int init=(start/24);
	// NSLog(@"inizio dalla corda %d",init);
	for (i=init;i<[openStringNotes count]-1;i++)
	{
		NSString *string=[openStringNotes objectAtIndex:i];
		// NSLog(@"cerco su openString %@",string);
		posOpenString = [notes indexOfObject:string];
		posNote = [notes indexOfObject:note];
		// NSLog(@"posOpenString %d - posNote %d",posOpenString,posNote);
		if (posNote<posOpenString) posNote+=12;
		if (posNote-posOpenString<6)
		{
			index=posNote-posOpenString+(i*24);
			// NSLog(@"trovata posizione %d",index);
			break;
		}
	}
	// NSLog(@"trovata posizione %d",index);
	return index;
}
*/
@end